package org.vgou.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* 
* Copyright (c) 2011, vgou All rights reserved.
* 
* @since Nov 27, 2011
* @author <a href="mailto:jason.hxx@gmail.com">jason</a>
* @version Id: Category.java Nov 27, 2011
* @comment 商品类型实体类
* 
*/
@Entity
//更新一个对象时,会生成动态SQL,当属性值发生变化时，才会包含到UPDATE语句中
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Table(name = "category")
public class Category implements Serializable {
	
	private static final long serialVersionUID = 3924398217548616693L;

	/** 编号 **/
	@Id
	@GeneratedValue
	@Column(name="id", length=19)
	private long id;
	
	/** 类型名称 **/
	@Column(name="name")
	private String name;
	
	/** 父级类型 **/
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="parentid")
	private Category parent;
	
	/** 子级类型集合 **/
	@OneToMany(mappedBy="parent", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private Set<Category> children = new HashSet<Category>();

	public Category() {
		super();
	}

	public Category(long id, String name, Category parent) {
		super();
		this.id = id;
		this.name = name;
		this.parent = parent;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Category getParent() {
		return parent;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}

	public Set<Category> getChildren() {
		return children;
	}

	public void setChildren(Set<Category> children) {
		this.children = children;
	}
	
	
}
